package com.swak.frame.command;


import java.lang.reflect.Method;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.alibaba.fastjson.JSON;
import com.swak.frame.aop.AspectAopUtils;
import com.swak.frame.command.fallback.SwakFallbackMethod;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@ComponentScan("com.swak.frame")
public class FallBackDemoServiceTest {

	@Resource
	private FallBackDemoService fallBackDemoService; 
	
	@Test
	public void testSwakFallBack() throws Throwable {
		Method commandMethod = AspectAopUtils.getDeclaredMethod(fallBackDemoService.getClass(), "getFallBack");
		SwakFallbackMethod swakFallbackMethod = SwakMethodProvider.getInstance().getFallbackMethod(fallBackDemoService.getClass(), commandMethod);
		System.out.println(JSON.toJSONString(swakFallbackMethod));
		Object result = swakFallbackMethod.executeWithArgs(fallBackDemoService, new Object[] {});
		System.out.println(JSON.toJSONString(result));
	}
}
